package org.afun.oldhand.user.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.oldhand.R;
import org.afun.oldhand.forum.adapter.ForumBottomItemAdapter;
import org.afun.oldhand.user.activity.user_item1_2;
import org.afun.oldhand.user.javabean.Youhuiquan;

import java.util.List;

public class UserYouhuiquanAdapter extends RecyclerView.Adapter<UserYouhuiquanAdapter.UserYouhuiquanAdapterHolder> {

    private List<Youhuiquan> data;
    private Context context;
    private OnUserYouhuiquanItemRecyclerItemClickListener onUserYouhuiquanItemRecyclerItemClickListener;

    public UserYouhuiquanAdapter(List<Youhuiquan> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public UserYouhuiquanAdapter.UserYouhuiquanAdapterHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate( R.layout.user_youhuiquan_listitem, parent, false);

        return new UserYouhuiquanAdapter.UserYouhuiquanAdapterHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull UserYouhuiquanAdapter.UserYouhuiquanAdapterHolder holder, int position) {
        holder.youhuiquanPic.setImageResource(data.get(position).getYouhuiquanPic());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class UserYouhuiquanAdapterHolder extends RecyclerView.ViewHolder{
        ImageView youhuiquanPic;

        public UserYouhuiquanAdapterHolder(@NonNull View itemView) {

            super(itemView);
            youhuiquanPic = itemView.findViewById(R.id.user_youhuiquan_pic);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onUserYouhuiquanItemRecyclerItemClickListener!=null){
                        onUserYouhuiquanItemRecyclerItemClickListener.onItemRecyclerItemClick(getAdapterPosition());
                    }
                }
            });

        }
    }

    public void setUserYouhuiquanItemClickListener(UserYouhuiquanAdapter.OnUserYouhuiquanItemRecyclerItemClickListener listener){
        onUserYouhuiquanItemRecyclerItemClickListener=listener;
    }

    public interface OnUserYouhuiquanItemRecyclerItemClickListener{
        void onItemRecyclerItemClick(int position);
    }
    
}
